import request from '../../utils/request'

export const getResources = () => {
    return request({
        url: '/wisdom-ac/resource/current_user_resource_list',
        method: 'get'
    })
}
export const listResource = (query) => {
    return request({
        url: '/wisdom-ac/resource/list',
        method: 'get',
        params: query
    })
}
export const saveApp = (data) => {
    return request({
        url: '/wisdom-ac/resource/save_app',
        method: 'post',
        data: data
    })
}
export const saveAppPage = (data) => {
    return request({
        url: '/wisdom-ac/resource/save_app_page',
        method: 'post',
        data: data
    })
}
export const saveAppPageElement = (data) => {
    return request({
        url: '/wisdom-ac/resource/save_app_page_element',
        method: 'post',
        data: data
    })
}
export const delResource = (resourceIds) => {
    return request({
        url: '/wisdom-ac/resource/'+resourceIds,
        method: 'delete'
    })
}
export const getResource = (resourceId) => {
    return request({
        url: '/wisdom-ac/resource/'+resourceId,
        method: 'get'
    })
}
export const saveUser = (data) => {
    return request({
        url: '/wisdom-ac/user',
        method: 'post',
        data: data
    })
}
export const delUser = (userIds) => {
    return request({
        url: '/wisdom-ac/user/'+userIds,
        method: 'delete'
    })
}
export const getUser = (userId) => {
    return request({
        url: '/wisdom-ac/user/'+userId,
        method: 'get'
    })
}
export const listUser = (query) => {
    return request({
        url: '/wisdom-ac/user/list',
        method: 'get',
        params: query
    })
}
export const resetUserPwd = (userId,password) => {
    const data = {
        "id":userId,
        "password":password
    }
    return request({
        url: '/wisdom-ac/user/resetPwd',
        method: 'put',
        data: data
    })
}
export const saveRole = (data) => {
    return request({
        url: '/wisdom-ac/role',
        method: 'post',
        data: data
    })
}
export const delRole = (roleId) => {
    return request({
        url: '/wisdom-ac/role/' + roleId,
        method: 'delete'
    })
}
export const getRole = (roleId) => {
    return request({
        url: '/wisdom-ac/role/'+roleId,
        method: 'get'
    })
}
export const listRole = (query) => {
    return request({
        url: '/wisdom-ac/role/list',
        method: 'get',
        params: query
    })
}
// 查询角色已授权用户列表
export function allocatedUserList(query) {
    return request({
        url: '/wisdom-ac/user/allocatedList',
        method: 'get',
        params: query
    })
}
export function unallocatedUserList(query) {
    return request({
        url: '/wisdom-ac/user/unallocatedList',
        method: 'get',
        params: query
    })
}
export function authUser(data) {
    return request({
        url: '/wisdom-ac/user/authUser',
        method: 'post',
        data: data
    })
}
export function authUserCancel(data) {
    return request({
        url: '/wisdom-ac/user/authUserCancel',
        method: 'post',
        data: data
    })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
    const data = {
        oldPassword: oldPassword,
        password: newPassword
    }
    return request({
        url: '/wisdom-ac/user/profile/updatePwd',
        method: 'post',
        data: data
    })
}
